﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HashTable
{
    public class HT<TKey, TValue> where TValue : class
    {
        private Element<TValue>[] table;

        public HT(int size = 97)
        {
            table = new Element<TValue>[size];
            for (int i = 0; i < table.Count(); i++)
            {
                table[i] = new Element<TValue>();
            }
        }

        public void Add(TKey key, TValue value)
        {
            int index = key.GetHashCode() % table.Count();
            if (index < 0)
                index = -index;
            table[index].Add(value);
        }

        public TValue[] Find(TKey key)
        {
            return table[key.GetHashCode() % table.Count()].Bucket;
        }

        public string Print()
        {
            string s = "";
            for (int i = 0; i < table.Count(); i++)
            {
                s += "index: " + i.ToString() + ": " + table[i].Print() + "\n";
            }
            return s;
        }
    }
}
